package cur.nature.component.springai.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 任务调度 Controller
 * 作者：Auto Generator By wujian
 * 生成日期：2024-04-28 18:27:31
 */
@Tag(name = "springai测试 接口")
@RestController
@RequestMapping("component/springai/v1/api/test")
@ConditionalOnProperty( value = {"cur.component.springai.controller.enable"})
public class Component_SpringAiController {

    private final OpenAiChatModel chatModel;
    private final ChatClient chatClient;

    @Autowired
    public Component_SpringAiController(OpenAiChatModel chatModel, ChatClient chatClient) {
        this.chatModel = chatModel;
        this.chatClient = chatClient;
    }

    @Operation(summary = "对话")
    @GetMapping("chat")
    public Map<String,String> login(@RequestParam String message) {
//        String response = chatClient.prompt("Tell me a joke").call().content();
//        System.out.println(response);
//        return Map.of("generation", response);
        return Map.of("generation", this.chatModel.call(message));
    }

    @Operation(summary = "对话2")
    @GetMapping("/ai/simple")
    public Map<String, String> completion(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
        return Map.of("completion", this.chatClient.prompt().user(message).call().content());
    }



}

